﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace RegEx
{
    class RegEx
    {
        static bool CheckNumber(string text)
        {
            bool isMatch = Regex.IsMatch(text, @"\A(0|-?[1-9]\d*)([\.|\,]\d+)?\Z");
            return isMatch;
        }

        static void CheckNumberTest()
        {
            string[] texts = 
            {
                "123",
                "0",
                "00",
                "01",
                "-0",
                "-1",
                "--1",
                "-11",
                "0.1",
                "12.",
                "12.0",
                "0.0",
                "0.00",
                ".1",
                ".",
                "1.1.1",
                "1..1",
                "00.1",
            };

            foreach (var item in texts)
            {
                Console.WriteLine(string.Format("{0}: {1}", item, CheckNumber(item)));
            }
        }

        static Dictionary<string, string> UrlParse(string url)
        {
            Regex regex = new Regex(@"\A((?<protocol>\w+):\\\\)?(?<server>\w[\w\d-]+(\.[\w\d-]+)*\.\w{2,4})(?<resourse>.*)\Z");
            Dictionary<string, string> urlElements = new Dictionary<string, string>();

            Match match = regex.Match(url);

            if (match.Success)
            {
                urlElements["protocol"] = match.Groups["protocol"].ToString();
                urlElements["server"] = match.Groups["server"].ToString();
                urlElements["resourse"] = match.Groups["resourse"].ToString();
            }

            return urlElements;
        }

        static void UrlParseTest()
        {
            string[] urls =
            {
                @"abv.bg",
                @"http:\\bigben.co.uk\i-taka-natatyk",
                @"http:\\bigben.co.uk",
                @"http:\\mnogo-gre6en-url",
                @"http:\\pak-gre6en-url..com\index.php",
            };

            foreach (var url in urls)
            {
                var urlElements = UrlParse(url);
                Console.WriteLine("URL: {0}", url);

                foreach (var element in urlElements)
                {
                    Console.WriteLine(string.Format("{0}: {1}", element.Key, element.Value));
                }
                Console.WriteLine();
            }
        }

        static string[] SplitSentences(string text)
        {
            // TODO da ne maha znacite
            string[] sentences = Regex.Split(text, @"\s*[\.\!\?]\s*");

            return sentences;
        }

        static void SplitSentencesTest()
        {
            string text = @"asdf asd fsa f a. asdfgf d!asd  gfds?";

            foreach (var item in SplitSentences(text))
            {
                Console.WriteLine(item);
            }
        }

        static void Main(string[] args)
        {
            //CheckNumberTest();

            //UrlParseTest();

            SplitSentencesTest();
        }
    }
}
